<template>
	<view class="">
		<my-search
			:is-show-border="true"
			placeholder="请输入商品名称、助记码、货号、条码" 
			@setval="onSearchDate"
		/>
		<uni-table ref="table" stripe type="selection" emptyText="暂无更多数据" @selection-change="selectionChange">
			<uni-tr>
				<!-- <uni-th align="center" width="60">图片</uni-th> -->
				<uni-th width="100">名称</uni-th>
				<uni-th align="center" width="60">价格</uni-th>
			</uni-tr>
			<uni-tr v-for="(item, index) in tableData" :key="index">
				<!-- <uni-td><image style="width:60rpx;height:60rpx; display:inline-block" :src="$imgUrl + item.FGoodImg" /></uni-td> -->
				<uni-td><view>{{item.FName}}</view></uni-td>
				<uni-td align="center"><text>{{item.FPrice}}</text></uni-td>
			</uni-tr>
		</uni-table>
		<u-gap height="86" bg-color="#f5f5f5" />
		<view class="fo-bx flex justify-between plr-20">
			<u-button class="w-45" @click="onCancel">取消</u-button>
			<u-button class="w-45" type="primary" @click="onupdata">确定</u-button>
		</view>
		<!-- <uni-pagination show-icon :page-size="searchData.page_size" :current="pageCurrent" :total="total" @change="change" /> -->
	</view>
</template>

<script>
	import MySearch from '@/components/search/index.vue'
	export default{
		components: {
			MySearch
		},
		props:{
			biitype:{
				type: Number,
				default: 1
			}
		},
		data(){
			return {
				tableData:[],
				searchData:{
					name:'',
					type: this.biitype,
					page_index: 1,
					page_size: 100,
				},
				reList:[]
			}
		},
		created() {
			this.getTableData()
		},
		methods: {
			onupdata(){
				if(this.reList.length!==0){
					this.$emit('seldata', this.reList)
					this.onCancel()
				}else{
					uni.showToast({
						title: '请选择商品',
						icon:'none',
					});
				}
			},
			onCancel(){
				this.$emit('cancel', false)
				this.$refs.table.clearSelection()
			},
			getTableData(){
				this.$reqGet('GetBillGoods', this.searchData).then(res=>{
					this.tableData = res.Data || []
				})
			},
			selectionChange(e){
				let ids = e.detail.index
				if(ids.length !==0){
					this.reList = ids.map(im=>this.tableData[im])
				}
			},
			onSearchDate(val){
				if(val !== ''){
					this.searchData.name = val 
					this.getTableData()
				}
			}
		}
	}
</script>

<style>
</style>